package com.daocao.ds.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.daocao.ds.R;
import com.daocao.ds.util.UI;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-5-15.
 */

public class BussinessBottomLayout extends LinearLayout {

    @BindView(R.id.img_icon_one)
    ImageView imgIconOne;
    @BindView(R.id.txt_one)
    TextView txtOne;
    @BindView(R.id.btn_one)
    LinearLayout btnOne;
    @BindView(R.id.img_icon_two)
    ImageView imgIconTwo;
    @BindView(R.id.txt_two)
    TextView txtTwo;
    @BindView(R.id.btn_two)
    LinearLayout btnTwo;
    @BindView(R.id.img_icon_three)
    ImageView imgIconThree;
    @BindView(R.id.txt_three)
    TextView txtThree;
    @BindView(R.id.btn_three)
    LinearLayout btnThree;
//    @BindView(R.id.img_icon_four)
//    ImageView imgIconFour;
//    @BindView(R.id.txt_four)
//    TextView txtFour;
//    @BindView(R.id.btn_four)
//    LinearLayout btnFour;
//    @BindView(R.id.img_icon_five)
//    ImageView imgIconFive;
//    @BindView(R.id.txt_five)
//    TextView txtFive;
//    @BindView(R.id.btn_five)
//    LinearLayout btnFive;

    private int selectPoi = 0;

    public BussinessBottomLayout(Context context) {
        super(context);
        init(context, null);
    }

    public BussinessBottomLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public BussinessBottomLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        inflate(context, R.layout.item_bussiness_bottom, this);
    }

    private int mIconRes[][] = {
            {R.mipmap.img_icon_one_unselect, R.mipmap.img_icon_one_select},
            {R.mipmap.img_icon_two_unselect, R.mipmap.img_icon_two_select},
            {R.mipmap.img_icon_three_unselect, R.mipmap.img_icon_three_select}
//            {R.mipmap.img_home_unselect_five, R.mipmap.img_home_select_five}

    };
    private int mTextColor[] = new int[]{0xffA6ACB4, 0xff0073FF};

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.bind(this);
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(int poi);

    }

    private void initStatus(int poi) {
        switch (poi) {
            case 0:
                txtOne.setTextColor(mTextColor[0]);
                imgIconOne.setImageResource(mIconRes[0][0]);
                break;
            case 1:
                txtTwo.setTextColor(mTextColor[0]);
                imgIconTwo.setImageResource(mIconRes[1][0]);
                break;
            case 2:
                txtThree.setTextColor(mTextColor[0]);
                imgIconThree.setImageResource(mIconRes[2][0]);
                break;
//            case 3:
//                txtFour.setTextColor(mTextColor[0]);
//                imgIconFour.setImageResource(mIconRes[3][0]);
//                break;
//            case 4:
//                txtFive.setTextColor(mTextColor[0]);
//                imgIconFive.setImageResource(mIconRes[4][0]);
//                break;
        }
    }

    private void selectStatus(int poi) {
        switch (poi) {
            case 0:
                txtOne.setTextColor(mTextColor[1]);
                imgIconOne.setImageResource(mIconRes[0][1]);
                break;
            case 1:
                txtTwo.setTextColor(mTextColor[1]);
                imgIconTwo.setImageResource(mIconRes[1][1]);
                break;
            case 2:
                txtThree.setTextColor(mTextColor[1]);
                imgIconThree.setImageResource(mIconRes[2][1]);
                break;
//            case 3:
//                txtFour.setTextColor(mTextColor[1]);
//                imgIconFour.setImageResource(mIconRes[3][1]);
//                break;
//            case 4:
//                txtFive.setTextColor(mTextColor[1]);
//                imgIconFive.setImageResource(mIconRes[4][1]);
//                break;
        }
    }

    public void selectPageOne() {
        if (onChooseListener != null) {
            onChooseListener.onClick(0);
        }
        if (selectPoi != 0) {
            initStatus(selectPoi);
            selectPoi = 0;
            selectStatus(selectPoi);
        }
    }

    public void selectPageTwo() {
        if (onChooseListener != null) {
            onChooseListener.onClick(1);
        }
        if (selectPoi != 1) {
            initStatus(selectPoi);
            selectPoi = 1;
            selectStatus(selectPoi);
        }
    }


    public void selectPageThree() {
        if (onChooseListener != null) {
            onChooseListener.onClick(2);
        }
        if (selectPoi != 2) {
            initStatus(selectPoi);
            selectPoi = 2;
            selectStatus(selectPoi);
        }
    }

//    public void selectPageFour() {
//        if (onChooseListener != null) {
//            onChooseListener.onClick(3);
//        }
//        if (selectPoi != 3) {
//            initStatus(selectPoi);
//            selectPoi = 3;
//            selectStatus(selectPoi);
//        }
//    }

//    public void selectPageFive() {
//        if (onChooseListener != null) {
//            onChooseListener.onClick(4);
//        }
//        if (selectPoi != 4) {
//            initStatus(selectPoi);
//            selectPoi = 4;
//            selectStatus(selectPoi);
//        }
//    }

    public void setSelectPage(int poi) {
        switch (poi) {
            case 0:
                selectPageOne();
                break;
            case 1:
                selectPageTwo();
                break;
            case 2:
                selectPageThree();
                break;
//            case 3:
//                selectPageFour();
//                break;
//            case 4:
//                selectPageFive();
//                break;
        }
    }

    @OnClick({R.id.btn_one, R.id.btn_two, R.id.btn_three})
    public void onViewClicked(View view) {
        if (UI.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.btn_one:
                selectPageOne();
                break;
            case R.id.btn_two:
                selectPageTwo();
                break;
            case R.id.btn_three:
                selectPageThree();
                break;
//            case R.id.btn_four:
//                selectPageFour();
//                break;
//            case R.id.btn_five:
//                selectPageFive();
//                break;

        }
    }
}
